﻿/*
 * @author: wizardc
 */

using System.IO;
using Dou.Utils;
using DouEditor.Utils;
using UnityEditor;

namespace DouEditor.Resource.Package
{
    /// <summary>
    /// 打 EXE 包
    /// </summary>
    public class PackExe
    {
        public void Pack(BuildRule buildRule)
        { 
            var buildPath = GetBuildPath(buildRule);
            EditorUtil.CreateDirByFilePath(buildPath);

            PlayerSettings.bundleVersion = buildRule.mainVersion;
            
            var scenePath = AssetDatabase.GetAssetPath(buildRule.sceneObj);
            BuildPipeline.BuildPlayer(new [] { scenePath },
                buildPath,
                EditorUserBuildSettings.activeBuildTarget,
                BuildOptions.None);
        }

        private string GetBuildPath(BuildRule buildRule)
        {
            var name = $"{buildRule.desc}_{buildRule.mainVersion}_{buildRule.hotFixedVersion}_{TimeUtil.FormatNowDate("yyyy_MM_dd_HH_mm_ss")}.exe";
            return Path.Combine(buildRule.packageOutputPath, "EXE", name);
        }
    }
}
